# coding=utf-8
import logging
import logging.handlers
import os.path
import time
from data import constant


def set_log_config():
    # 2.创建日志器对象/设置日志级别
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # project = os.getcwd()
    # project = "E:/00Testing/test4yunkai_admin"
    project = constant.PATH
    current_date = time.strftime('%Y-%m-%d %H-%M-%S', time.localtime(time.time()))
    file_name = project + '/result/log/' + current_date + '.log'

    # 3.创建handler对象，用于输出到控制台
    ls = logging.StreamHandler()
    fh = logging.FileHandler(file_name,mode="w",encoding="UTF-8")
    fh.setLevel(logging.INFO)
    # 4. 创建格式化器
    fmt = '%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(funcName)s:%(lineno)d] - %(message)s'
    formatter = logging.Formatter(fmt=fmt)
    # 5. 将格式化器添加到处理器
    ls.setFormatter(formatter)
    fh.setFormatter(formatter)
    # 6. 添加处理器到日志器
    logger.addHandler(ls)
    logger.addHandler(fh)